#!/usr/bin/env python
#coding:utf-8
import os,cmd,getpass

def search(curpath,s):
    L = os.listdir(curpath)  # 列出当前目录下所有文件
    for subpath in L:  # 遍历当前目录所有文件
        if os.path.isdir(os.path.join(curpath, subpath)):  # 若文件仍为目录，递归查找子目录
            newpath = os.path.join(curpath, subpath)
            search(newpath, s)
        elif os.path.isfile(os.path.join(curpath, subpath)):  # 若为文件，判断是否包含搜索字串
            if s in subpath:
                return os.path.join(curpath, subpath)

class Query(cmd.Cmd):
    intro = '用户信息查询系统，输入 help 或者?查看帮助。\n'
    prompt = 'query>'

    def do_exit(self,_):
        '退出'
        exit(0)

    def do_lsbin(self,_):
        '列出bin目录'
        search('/',"mysqld")

    def do_whoami(self,_):
        'whoami'
        getpass.getuser()





if __name__ == '__main__':
    Query().cmdloop()

# See PyCharm help at https://www.jetbrains.com/help/pycharm/
